home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7232 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: newsxfer2.itd.umich.edu!agate!kaskel
  2. From: kaskel@durban.berkeley.edu (Bruce Kaskel)
  3. Newsgroups: comp.lang.pascal.misc,comp.lang.c++,comp.lang.c,comp.lang.pascal.borland
  4. Subject: Re: Tough FACTORIAL math problem...
  5. Date: 22 Feb 1996 07:01:46 GMT
  6. Organization: U.C. Berkeley Math. Department.
  7. Message-ID: <4gh4cq$8eo@agate.berkeley.edu>
  8. References: <4fr8be$ass@news.iconn.net> <4g2n5u$kqj@sun001.spd.dsccc.com> <danpop.824595562@rscernix> <4gaucn$cdu@beyond.escape.com>
  9. NNTP-Posting-Host: durban.berkeley.edu
  10.  
  11. In article <4gaucn$cdu@beyond.escape.com>,
  12. Ken Nahshon <viking@escape.com> wrote:
  13. >Who origianlly asked about this problem...?
  14. >This person is obviousely a serious loser because this was one of the 
  15. >qualifying round problems for the United States of America Computing 
  16. >Olypiad(USACO).  The problem is EXTREMELY simple.  All that must be done 
  17. >is remove all the trailing zeros after each iteration and (the way I did 
  18. >it) minus 10000 from the total if the total is greater than 10000.  
  19. >Another, cleaner solution is to use the modulus operator.  
  20. >
  21. >ps I did this, and speak from expierience. MINE WORKS! :)
  22.  
  23.  
  24. So after you have finished the n-th iteration, you have multiplied your
  25. number by n, removed the trailing zeros, and subtracted 10000 until the
  26. number is not greater than 10000. Are you claiming that you end up with
  27. a number with the same last digit as n! ?
  28.  
  29. Strictly speaking this is not correct.
  30.  
  31. Take the 3125-th iteration. Your algorithm yields 995. 
  32. But the rightmost non-zero digit of 3125! is not 5.
  33.  
  34. --Bruce Kaskel
  35.  
  36.  
  37.